const parseJwt = (token) => {
    try {
      const base64Url = token.split('.')[1];
      const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
      const payload = JSON.parse(atob(base64));
      return payload;
    } catch (error) {
      console.error('解析 JWT 失败:', error);
      return null;
    }
};
  
export const setCookie = (token) => {
    let { exp } = parseJwt(token);
    const now = Math.floor(Date.now() / 1000);
    const maxAge = exp - now;
    console.log('剩余时间:', maxAge);
    
    document.cookie = `token=${ token }; path=/; max-age=${ maxAge }; secure`;
}